package com.faradel.pharmapp.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.faradel.pharmapp.entities.Patient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faradel.pharmapp.dao.PatientDAO;

@Service("patientServiceImpl")
public class PatientServiceImpl implements PatientServiceInterface
{
    @Resource
    PatientDAO patientDaoImpl;

    @Override
    @Transactional(readOnly = false)
    public void addPatient(Patient patient)
    {
        patientDaoImpl.save(patient);
    }

    @Override
    @Transactional(readOnly = false)
    public void updatePatient(Patient patient)
    {
        patientDaoImpl.update(patient);
    }

    @Override
    @Transactional(readOnly = false)
    public void deletePatient(Patient patient)
    {
        patientDaoImpl.delete(patient);
    }

    @Override
    @Transactional(readOnly = true)
    public Patient getPatientById(int id)
    {
        return patientDaoImpl.get(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<Patient> getAllPatient()
    {
        return (List<Patient>) patientDaoImpl.selectAll();
    }

    @Override
    @Transactional(readOnly = true)
    public List<Patient> getPatientByColumns(Map<String, String> map)
    {
        return patientDaoImpl.findByColumn(map);
    }

}
